package com.sdtele.tta.operation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.User;
import com.sdtele.tta.models.VoteOption;
import com.sdtele.tta.models.VoteScore;
import com.sdtele.tta.models.VoteTask;

public class OperationGetVoteScoreDetail extends Operation {

	public JsonResponse handle(JsonRequest jsonRequest) {
		System.out.println("OperationLogin:req=" + jsonRequest);
		JsonResponse jres = new JsonResponse();
		User curUser = (User) request.getSession().getAttribute("user");
		if (curUser == null) {
			jres.setStatus(1);
			jres.setMessage("用户未登录");
			return jres;
		}		
		long voteId = jsonRequest.getJsonObject().get("voteId").getAsLong();
		long userId=jsonRequest.getJsonObject().get("userId").getAsLong();
		List<VoteScore> voteScore=Dac.getInstance().getVotescore(voteId, userId);
		List<Map<String,Object>> voteScoreList=new ArrayList<Map<String,Object>> ();
		for(VoteScore v:voteScore) {
			Map<String, Object> voteMap = new HashMap<String, Object>();
			String voteOptionName=Dac.getInstance().getVoteOptionbyId(v.getVoteOptionId()).getVoteOptionName();
			voteMap.put("score", v);
			voteMap.put("voteOptionName", voteOptionName);
			voteScoreList.add(voteMap);
		}
		
		jres.setStatus(0);
		jres.setMessage("当前用户具体投票信息");
		jres.setEntity(voteScoreList);
		return jres;

	}

}